//
//  ClassificationViewController.m
//  BeautifulShoppings
//
//  Created by GivenBmli on 16/9/5.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ClassificationViewController.h"
#import "Strategy.h"
#import "Present.h"
#import "StrategyCollectionView.h"
#import "StrategyDetailsViewController.h"
#import "PresentDetailsViewController.h"
#import "BigStrategyCollectionReusableView.h"
#import "StrategyCollectionViewCell.h"
#import "StrategyUpViewController.h"
#import "GiftPickViewController.h"
#import "JXLDayAndNightMode.h"
#import "ToolModel.h"
#import "TAMacro.h"
@interface ClassificationViewController ()<UIScrollViewDelegate,StrategyDelegate,PresentDelegate,StrategyBigDelegate>
@property (nonatomic,strong)UISegmentedControl * Segmented;
@property (nonatomic,strong)UIScrollView * scrollView;

@end

@implementation ClassificationViewController
- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.translucent= YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self foundUISegmentedControl];
    [self FoundUIScrollView];
    [self StrategyAndPresentView];
    [self foundUpButten];
    [self nightModel];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.98 green:0.29 blue:0.31 alpha:1.00]];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    
    
}
- (void)foundUISegmentedControl {
    
    NSArray *SegmentedArray = [[NSArray alloc]initWithObjects:@"攻略",@"礼物", nil];
    self.Segmented = [[UISegmentedControl alloc]initWithItems:SegmentedArray];
    self.Segmented.selectedSegmentIndex = 0;
    self.Segmented.tintColor = [UIColor whiteColor];
    self.Segmented.frame = CGRectMake(0, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT/20);
    self.navigationItem.titleView = self.Segmented;
    [self.Segmented addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
}
- (void)FoundUIScrollView {
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH , SCREEN_HEIGHT)];
    [self.view addSubview:self.scrollView];
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 2, 0 );
    self.scrollView.pagingEnabled = YES;//分页效果
    self.scrollView.bounces = NO;
    self.scrollView.delegate =self;
}
- (void)StrategyAndPresentView {
    Strategy *strategy  = [[Strategy alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    strategy.delegate = self;
    strategy.deledages =self;
    [self.scrollView addSubview:strategy];
    Present *present = [[Present alloc]initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    present.delegate = self;
    [self.scrollView addSubview:present];
}
- (void)click:(UISegmentedControl *)sender {
    if (self.Segmented.selectedSegmentIndex == 0) {
        self.scrollView.contentOffset = CGPointMake(0 , -64);
    }else{
        self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH, -64);
    }
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSInteger i = self.scrollView.contentOffset.x / SCREEN_WIDTH;
    if (i == 0) {
        self.Segmented.selectedSegmentIndex = 0;
    }else{
        self.Segmented.selectedSegmentIndex = 1;
    }
}
- (void)foundUpButten {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH  , SCREEN_HEIGHT/20);
    [button jxl_setDayMode:^(UIView *view) {
        button.backgroundColor = [UIColor whiteColor];
    } nightMode:^(UIView *view) {
        button.backgroundColor = [UIColor grayColor];
    }];
    [button setTitle:@"选礼神器" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.scrollView addSubview:button];
    [button addTarget:self action:@selector(TOPickGift:) forControlEvents:UIControlEventTouchUpInside];
}
// 专题跳转
- (void)didClickSelectItemAtIndexPathStrategyBig:(NSIndexPath *)indexPath str:(NSString *)str {
    self.hidesBottomBarWhenPushed = YES;
    StrategyUpViewController *strategyUpVC = [[StrategyUpViewController alloc]init];
    strategyUpVC.str = str;
    [self.navigationController pushViewController:strategyUpVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
// 攻略跳转
- (void)didClickSelectItemAtIndexPathStrategy:(NSIndexPath *)indexPath str:(NSString *)str STR:(NSString *)STR IMAGE:(NSString *)IMAGE {
    self.hidesBottomBarWhenPushed = YES;
    StrategyDetailsViewController *strategyDetailsVC = [[StrategyDetailsViewController alloc]init];
    strategyDetailsVC.str = str;
    strategyDetailsVC.STR = STR;
    strategyDetailsVC.IMAGE = IMAGE;
    ToolModel *tool = [[ToolModel alloc]init];
    tool.title = STR;
    tool.cover_image_url = IMAGE;
    tool.Id = str;
    [self.navigationController pushViewController:strategyDetailsVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
// 礼物跳转
- (void)didClickSelectItemAtIndexPathPresent:(NSIndexPath *)indexPath str:(NSString *)str {
    self.hidesBottomBarWhenPushed = YES;
    PresentDetailsViewController *presentDetailsVC = [[PresentDetailsViewController alloc]init];
    presentDetailsVC.str = str;
    [self.navigationController pushViewController:presentDetailsVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
- (void)TOPickGift:(UIButton *)sender {
    self.hidesBottomBarWhenPushed = YES;
    GiftPickViewController *pickGiftVC = [[GiftPickViewController alloc]init];
    [self.navigationController pushViewController:pickGiftVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}

- (void)nightModel {
    //设置日间和夜间两张状态
    [self.view jxl_setDayMode:^(UIView *view) {
        //设置日间模式
        view.backgroundColor = [UIColor whiteColor];
        
    } nightMode:^(UIView *view) {
        view.backgroundColor = [UIColor colorWithRed:0.12 green:0.14 blue:0.15 alpha:1.00];
    }];
    [self.navigationController.navigationBar jxl_setDayMode:^(UIView *view) {
        UINavigationBar *bar = (UINavigationBar *)view;
        //改变状态栏前景颜色
        bar.barStyle = UIBarStyleDefault;
        bar.barTintColor = [UIColor colorWithRed:1.000 green:0.431 blue:0.427 alpha:1.000];
        //        bar.barTintColor = [UIColor redColor];
    } nightMode:^(UIView *view) {
        UINavigationBar *bar = (UINavigationBar *)view;
        //改变状态栏前景颜色
        bar.barStyle = UIBarMetricsDefault;
        bar.barTintColor = [UIColor colorWithRed:0.12 green:0.14 blue:0.15 alpha:1.00];
    }];
    
}

@end
